package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.xs.XsStore;
import com.ruoyi.system.service.IXsStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 写稿店铺Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/system/store")
public class XsStoreController extends BaseController
{
    @Autowired
    private IXsStoreService xsStoreService;

    /**
     * 查询写稿店铺列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XsStore xsStore)
    {
        startPage();
        List<XsStore> list = xsStoreService.selectXsStoreList(xsStore);
        return getDataTable(list);
    }

    /**
     * 查询全部店铺
     * @param xsStore
     * @return
     */
    @GetMapping("/option")
    public AjaxResult option(XsStore xsStore)
    {
        xsStore.setState(0L);
        return success(xsStoreService.selectXsStoreList(xsStore));
    }

    /**
     * 导出写稿店铺列表
     */
    @Log(title = "写稿店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsStore xsStore)
    {
        List<XsStore> list = xsStoreService.selectXsStoreList(xsStore);
        ExcelUtil<XsStore> util = new ExcelUtil<XsStore>(XsStore.class);
        util.exportExcel(response, list, "写稿店铺数据");
    }

    /**
     * 获取写稿店铺详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xsStoreService.selectXsStoreById(id));
    }

    /**
     * 新增写稿店铺
     */
    @Log(title = "写稿店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody XsStore xsStore)
    {
        return toAjax(xsStoreService.insertXsStore(xsStore));
    }

    /**
     * 修改写稿店铺
     */
    @Log(title = "写稿店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody XsStore xsStore)
    {
        return toAjax(xsStoreService.updateXsStore(xsStore));
    }

    /**
     * 删除写稿店铺
     */
    @Log(title = "写稿店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xsStoreService.deleteXsStoreByIds(ids));
    }
}
